clear
set more off

use "Study_2_data.dta"

tab partisanship
// I recode the partisanship to have fewer categories, and drop those stating other and green party (n=9 and n=15 observations)
tab partisanship,nolab
// 1-republican party, 2-democratic party, 3-green party, 4-independents, 5-other 
recode partisanship (1=1)(2=2)(3=.)(4=3)(5=.)
tab partisanship


tab edu
tab ageinyears

label var news_corona "news exposure"

factor aot_1 aot_2 aot_3 aot_4 aot_5
alpha aot_1 aot_2 aot_3 aot_4 aot_5
// those >0.40
gen aot_index=(aot_1+aot_2+aot_4+aot_5)

factor cm_1 cm_2 cm_3 cm_4 cm_5
alpha cm_1 cm_2 cm_3 cm_4 cm_5
gen cm=(cm_1+cm_2+cm_3+cm_4+cm_5)

factor trust_congress trust_legal trust_pol trust_polit trust_party
gen poltrust=(trust_congress+trust_legal+trust_pol+trust_polit+trust_party)

/// something is happening with the variable trust_scient, so I create a copy variable to see if I could then standardize it properly. // yes, it worked. 

tab trust_scient
gen trustsci=trust_scient
tab trustsci


// standardizing the variables for ease in interpretation [0,1]

	foreach var in poltrust aot_index cm intertrust trustCA trustsci {
		qui sum `var'
		replace `var' = (`var' - `r(min)') / (`r(max)'-`r(min)')

	}

	foreach var in poltrust aot_index cm intertrust trustCA trustsci {
tab `var' 
}

********************************************************************************
**************************** TABLE 1 *******************************************
********************************************************************************

//w/o covariates
reg change_misp i.treatment
estimates store m1
// w/ covariates
reg change_misp i.treatment gender age_cat edu ib(1).race ideology ib(2).partisanship poltrust trustsci intertrust trustCA news_corona cm aot_index
estimates store m2
estout m1 m2, cells(b(star fmt(3)) se(par fmt(2)))  stats(r2)

sum change_misp

/// wald test
reg change_misp i.treatment
test 2.treatment=3.treatment
/*
 ( 1)  2.treatment - 3.treatment = 0

       F(  1,  1159) =    4.72
            Prob > F =    0.0300
*/
// so then, we have performed Wald tests.? I´m not entirely sure about it to be honest. 


/////
sum change_misp

/// to see what this effect mean in standardized terms, we standardize the change variable by the control condition´s mean and sd. 

sum change_misp if treatment==1
gen stanchange=(change_misp-.0284238)/.5863016

reg stanchange i.treatment
estimates store m1
// w/ covariates
reg change_misp i.treatment gender age_cat edu ib(1).race ideology ib(2).partisanship poltrust trustsci intertrust trustCA news_corona cm aot_index
estimates store m2
estout m1 m2, cells(b(star fmt(3)) se(par fmt(2)))  stats(r2)



********************************************************************************
**************************** ADDITIONAL TESTS***********************************
********************************************************************************

// Nyhan and Reifler Strategy

// rescaling the variables so that the greater numbes indicate more accurate beliefs.
fre mis_labmade
recode mis_labmade (1=5 "not accurate") (2=4 "probably not accurate") (3=3 "unsure") (4=2 "probably accurate") (5=1 "accurate"),gen(pre)
tab mis_labmade
tab pre


fre post_mis_labmade
recode post_mis_labmade (1=5 "not accurate") (2=4 "probably not accurate") (3=3 "unsure") (4=2 "probably accurate") (5=1 "accurate"),gen(post)
tab post_mis_labmade
tab post

reg post i.treatment pre
estimates store m1
// w/ covariates
reg post i.treatment pre gender age_cat edu ib(8).race ideology ib(2).partisanship poltrust trustsci intertrust trustCA news_corona cm aot_index
estimates store m2
estout m1 m2, cells(b(star fmt(3)) se(par fmt(2)))  stats(r2)

// Manipulation Check Question

tab manipulation_check
tab treatment   // control, expert and minipublic

gen compliance=.
replace compliance=1 if manipulation_check==4&treatment==1   //control
replace compliance=0 if manipulation_check==4&treatment!=1   //control

replace compliance=1 if manipulation_check==1&treatment==2	//expert
replace compliance=0 if manipulation_check==1&treatment!=2	//expert

replace compliance=1 if manipulation_check==2&treatment==3	//mini-public
replace compliance=0 if manipulation_check==2&treatment!=3	//mini-public

replace compliance=0 if manipulation_check==3

tab compliance
tab treatment

by treatment, sort : tabulate compliance

by treatment, sort : tabulate manipulation_check




*****

reg change_misp i.treatment if compliance==1
estimates store m1
// w/ covariates
reg change_misp i.treatment gender age_cat edu ib(8).race ideology ib(2).partisanship poltrust trustsci intertrust trustCA news_corona cm aot_index if compliance==1
estimates store m2
estout m1 m2, cells(b(star fmt(3)) se(par fmt(2)))  stats(r2)

******

// Treating the "don´t know" as missing values, and deleting them list-wise and rerunning the analyses

fre mis_labmade
fre post_mis_labmade

recode mis_labmade (3=.) (4=3)(5=4),gen (m1)
tab mis_labmade
tab m1

recode post_mis_labmade (3=.) (4=3)(5=4),gen (m2)
fre post_mis_labmade
fre m2

gen changem=(m2-m1)
fre changem
recode changem (-3=3)(-2=2)(-1=1)(0=0)(1=-1)(2=-2)		//to make the positive coefficient to show correction

reg changem i.treatment
estimates store m1
// w/ covariates
reg changem i.treatment gender age_cat edu ib(8).race ideology ib(2).partisanship poltrust trustsci intertrust trustCA news_corona cm aot_index
estimates store m2
estout m1 m2, cells(b(star fmt(3)) se(par fmt(2)))  stats(r2)

/// for descriptives recoding the political ideology variable. 
recode ideology (0 1 2 3 4=1 "left")(5=2 "middle")(6 7 8 9 10=3 "right"), gen(ideol_cat)

tab ideology
tab ideol_cat

	foreach var in gender age_cat edu race partisanship ideol_cat {
tab `var' 
}


//// THE BALANCE TESTS ////

orth_out gender age_cat edu race partisanship ideol_cat, by(treatment) replace se compare test count
